<%
layout("/layouts/platform.html"){
%>

<section class="content-wrap bg-white">
    <header class="header navbar bg-white shadow">
        <div class="btn-group tool-button">
            <a class="btn btn-primary navbar-btn" href="${base}/platform/sys/role" data-pjax><i class="ti-angle-left"></i> 返回</a>
            <a class="btn btn-primary navbar-btn" href="${base}/platform/sys/role/selectUser" data-toggle="modal" data-target="#dialogUserSelect"><i class="ti-plus"></i> 添加用户到 [${obj.name!}] 角色</a>
            <button class="btn btn-danger navbar-btn" onclick="delCheck()"><i class="ti-close"></i> 从 [${obj.name!}] 角色中删除用户</button>
        </div>
        <div class="pull-right offscreen-right">
            <button class="btn btn-primary navbar-btn" onclick="sublime.toggleFilter('.cd-panel')"><i
                    class="fa fa-sliders"></i> 筛选
            </button>
        </div>
    </header>
    <div class=panel-body style="padding-top: 50px;">
        <div class="table-responsive no-border">
            <input id="unitid" type="hidden">
            <input id="roleid" type="hidden" value="${obj.id!}">
            <table id="mydata" class="table table-bordered table-striped mg-t datatable">
                <thead>
                <tr>
                    <th>用户名</th>
                    <th>姓名/昵称</th>
                    <th>状态</th>
            </table>
        </div>
    </div>
</section>
<div class="cd-panel from-right">
    <header class="cd-panel-header">
        <h4>高级筛选</h4>
    </header>
    <div class="cd-panel-container">
        <div class="cd-panel-content shadow">
            <div class="form-group">
                <label for="loginname">用户名</label>
                <input type="text" id="loginname" name="loginname" onclick="this.value=''" class="form-control" placeholder="用户名" autofocus>
            </div>
            <div class="form-group">
                <label for="username">姓名</label>
                <input type="text" id="username" name="username" onclick="this.value=''" class="form-control" placeholder="姓名/昵称">
            </div>
            <button id="searchBtn" type="button" class="btn btn-default">查询</button>
        </div>
    </div>
</div>
<div id="dialogUserSelect" class="modal fade bs-modal-sm" tabindex="-3" role="dialog" aria-hidden="true">
    <div class="modal-dialog" style="width: 700px;">
        <div class="modal-content" style="width: 700px;">

        </div>
    </div>
</div>
<script language="JavaScript">
    var datatable;
    function initDatatable() {
        datatable = $('#mydata').DataTable({
            "dom": '<"toolbar">frtip',
            "searching":false,
            "processing": false,
            "serverSide": true,
            "select": true,
            "ordering": true,
            "language": {
                "url": "${base}/assets/plugins/datatables/cn.json"
            },
            "preDrawCallback": function () {
                sublime.showLoadingbar($(".main-content"));
            },
            "drawCallback": function () {
                sublime.closeLoadingbar($(".main-content"));
            },
            "ajax": {
                "url": "${base}/platform/sys/role/userData",
                "type": "post",
                "data": function (d) {
                    d.roleid = $('#roleid').val();
                    d.loginname = $('#loginname').val();
                    d.username = $('#username').val();
                }
            },
            "order": [[0, "desc"]],
            "columns": [
                {"data": "loginname", "bSortable": true},
                {"data": "username", "bSortable": true},
                {"data": "disabled", "bSortable": true}
            ],
            "columnDefs": [
                {
                    "render": function (data, type, row) {
                        if (!data) {
                            return '<i id="disable_' + row.id + '" class="fa fa-circle text-success ml5"></i>';
                        } else {
                            return '<i id="disable_' + row.id + '" class="fa fa-circle text-danger ml5"></i>';
                        }
                    },
                    "targets": 2
                }
            ]
        });
        datatable.on('click', 'tr', function () {
            $(this).toggleClass('selected');
        });
        $("#searchBtn").on('click', function () {
            datatable.ajax.reload();
        });
    }
    function delCheck(){
        var chks = datatable.rows('.selected').data();
        if (chks.length > 0) {
            var ids = [];
            $.each(datatable.rows('.selected').data(), function (i, n) {
                ids.push(n.id);
            });
            $.post("${base}/platform/sys/role/delUser", {menuIds: ids.toString(),roleid: $('#roleid').val()}, function (data) {
                if (data.code == 0) {
                    Toast.success(data.msg);
                    datatable.ajax.reload();
                } else {
                    Toast.error(data.msg);
                }
            }, "json");
        }else{
            Toast.warning("请先选择用户！");
        }
    }
    $(document).ready(function () {
        initDatatable();
        $("#dialogUserSelect").on("hidden.bs.modal", function () {
            $(this).removeData("bs.modal");
        });
    });

</script>

<%}%>